//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.example.controller;

import com.example.common.Result;
import com.example.entity.Article;
import com.example.service.ArticleService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping({"/article"})
public class ArticleController {
    @Resource
    private ArticleService articleService;

    public ArticleController() {
    }

    @GetMapping({"/selectAll"})
    public Result selectAll(Article article) {
        List<Article> list = this.articleService.selectAll(article);
        return Result.success(list);
    }

    @GetMapping({"/selectById/{id}"})
    public Result selectById(@PathVariable Integer id, @PathVariable String no) {
        Article article = this.articleService.selectById(id);
        return Result.success(article);
    }

    @GetMapping({"/selectByOne"})
    public Result selectByOne(@RequestParam Integer id, @RequestParam(required = false) String no) {
        Article article = this.articleService.selectById(id);
        return Result.success(article);
    }

    @GetMapping({"/selectList"})
    public Result selectList(Article article) {
        List<Article> list = this.articleService.selectList(article);
        return Result.success(list);
    }

    @GetMapping({"/selectPage"})
    public Result selectPage(Article article, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Article> pageInfo = this.articleService.selectPage(article, pageNum, pageSize);
        return Result.success(pageInfo);
    }

    @PostMapping({"/add"})
    public Result add(@RequestBody Article article) {
        this.articleService.add(article);
        return Result.success();
    }

    @PutMapping({"/updateById"})
    public Result updateById(@RequestBody Article article) {
        this.articleService.updateById(article);
        return Result.success();
    }

    @DeleteMapping({"/deleteById/{id}"})
    public Result deleteById(@PathVariable Integer id) {
        this.articleService.deleteById(id);
        return Result.success();
    }

    @DeleteMapping({"/deleteBatch"})
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        this.articleService.deleteBatch(ids);
        return Result.success();
    }
}
